/**
 * 项目名：	Rumba Plan
 * 
 * 版权所有(C)，上海海鼎信息工程股份有限公司，2007，所有权利保留。
 * 
 * 文件名：	ActionLogFilter.java
 * 模块说明：	
 * 修改历史：
 * 2007-2-9 - Administrator - 创建。
 */
package com.hd123.rumba.action.log;

import java.util.Date;

import com.hd123.rumba.request.JspLib;
import com.hd123.rumba.runtime.FormatSettings;

/**
 * 操作日志筛选条件 | 界面数据对象
 * 
 * @author zyb
 * 
 */
public class ActionLogFilter {

  /** 时间大于等于 */
  private Date timeAfter;
  /** 时间小于等于 */
  private Date timeBefore;
  /** 操作人类似于 */
  private String operatorLike;
  /** 调用模块.标题类似于 */
  private String actionCaptionLike;
  /** 事件类似于 */
  private String eventLike;
  /** 消息类似于 */
  private String messageLike;

  public String getActionCaptionLike() {
    return actionCaptionLike;
  }

  public void setActionCaptionLike(String actionCaptionLike) {
    this.actionCaptionLike = actionCaptionLike;
  }

  public String getEventLike() {
    return eventLike;
  }

  public void setEventLike(String eventLike) {
    this.eventLike = eventLike;
  }

  public String getMessageLike() {
    return messageLike;
  }

  public void setMessageLike(String messageLike) {
    this.messageLike = messageLike;
  }

  public String toJSForRQuery(String qryName, String alias) throws Exception {
    StringBuffer sb = new StringBuffer();
    sb.append("var sce = new RSCE();\n");
    sb.append("sce.operator = RSCE.VALUE_OPERATOR_AND;\n");

    if (timeAfter != null) {
      sb
          .append("var d1 = parseDate('" + JspLib.format(timeAfter, FormatSettings.SDFyMdHms)
              + "');");
      sb.append("sce.append(RSCE.cond('" + alias + ".time >= ?', d1));\n");
    }
    if (timeBefore != null) {
      sb.append("var d2 = parseDate('" + JspLib.format(timeBefore, FormatSettings.SDFyMdHms)
          + "');");
      sb.append("sce.append(RSCE.cond('" + alias + ".time <= ?', d2));\n");
    }
    if (operatorLike != null)
      sb.append("sce.append(RSCE.cond('" + alias + ".operator like ?', '"
          + operatorLike.toUpperCase() + "', RSCE.WC_BOTH));\n");
    if (actionCaptionLike != null)
      sb.append("sce.append(RSCE.cond('" + alias + ".actionCaption like ?', '" + actionCaptionLike
          + "', RSCE.WC_BOTH));\n");
    if (eventLike != null)
      sb.append("sce.append(RSCE.cond('" + alias + ".event like ?', '" + eventLike
          + "', RSCE.WC_BOTH));\n");
    if (messageLike != null)
      sb.append("sce.append(RSCE.cond('" + alias + ".message like ?', '" + messageLike
          + "', RSCE.WC_BOTH));\n");

    sb.append("if (isDefined(sce.parameters))\n");
    sb.append("  " + qryName + ".setWhere(sce);\n");
    return sb.toString();
  }

  public String getOperatorLike() {
    return operatorLike;
  }

  public void setOperatorLike(String operatorLike) {
    this.operatorLike = operatorLike;
  }

  public Date getTimeAfter() {
    return timeAfter;
  }

  public void setTimeAfter(Date timeAfter) {
    this.timeAfter = timeAfter;
  }

  public Date getTimeBefore() {
    return timeBefore;
  }

  public void setTimeBefore(Date timeBefore) {
    this.timeBefore = timeBefore;
  }

}
